@extends('layouts.app')

@section('title')添加文章 @endsection

@section('css')
    <link rel="stylesheet" href="{{ asset('plugins/summernote/css/summernote.css') }}">
    <link rel="stylesheet" href="{{ asset('plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css') }}">
@endsection

@section('content')
    <div class="tabs">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h6><i class="fa fa-check-circle-o bk-fg-warning"></i>@yield('title')</h6>
            </div>
            <div class="panel-body">
                <form id="article-add-edit-form" class="form-horizontal" method="post" enctype="multipart/form-data"
                        action="{{ $article ? route('articles-edit', [$article->id]) : route('articles-add') }}">
                    {!! csrf_field() !!}
                    @if($article)
                        <input type="hidden" name="article_id" value="{{ $article->id }}">
                    @endif
                    <div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label" for="title">标题 <span class="required">*</span></label>
                            <div class="col-sm-7">
                                <input type="text" name="title" id="title" class="form-control"
                                        value="{{ $article ? $article->title : '' }}" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label" for="category">分类 <span
                                        class="required">*</span></label>
                            <div class="col-sm-7">
                                <select class="form-control" name="category_id" id="category" required>
                                    @foreach($categories as $category)
                                        <option value="{{ $category->id }}">{{ $category->name }}</option>
                                    @endforeach
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">发布时间 <span class="required">*</span></label>
                            <div class="col-sm-7">
                                <div class="radio-custom radio-inline">
                                    <input type="radio" name="is-publish-now" id="publish-right-now" value="1" checked>
                                    <label for="publish-right-now">立即发布</label>
                                </div>
                                <div class="radio-custom radio-inline">
                                    <input type="radio" name="is-publish-now" id="publish-timer" value="0"
                                            @if($article)checked @endif>
                                    <label for="publish-timer">定时发布</label>
                                </div>
                            </div>
                        </div>
                        <div class="form-group" id="publish-time-group" @if(!$article)style="display: none;"@endif>
                            <label class="col-sm-3 control-label" for="publish_at">选择日期</label>
                            <div class="col-sm-7">
                                <div class="input-group">
                                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                    <input type="text" id="publish_at" name="publish_at" class="form-control"
                                            value="{{ $article ? $article->publish_at : '' }}">
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label" for="category">图片 &nbsp;</label>
                            <div class="col-sm-6 bk-padding-off-left">
                                <input type="hidden" name="img_id" value="{{ $article ? $article->img_id : '' }}">
                                <input type="file" name="article-thumbnail" id="article-thumbnail" accept="image/*"
                                       class="col-md-7 col-xs-9" value="1">
                                <span class="help-block">建议使用流行的最新浏览器, 可以本地快速预览图片</span>
                            </div>
                            <div class="clearfix bk-margin-5"></div>

                            <div class="col-sm-6 col-sm-offset-3" id="article-image-thumbnail"
                                 @if(!$article || !$article->img_id)style="display: none;" @endif>
                                <img alt="广告图片" class="thumbnail" style="max-width: 100%;"
                                     src="{{ $article ? $article->getPicture() : '' }}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label" for="summer-note-content">内容
                                <span class="required">*</span></label>
                            <div class="col-sm-7">
                                <textarea name="content" id="summer-note-content" data-height="450" required>
                                    {{ $article ? $article->content : '' }}</textarea>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-7 col-sm-offset-3">
                                <button class="bk-margin-5 btn btn-info" type="submit">保存</button>
                                <button type="reset" class="bk-margin-5 btn btn-default">清空</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
@stop

@section('js')
    <script src="{{ asset('plugins/moment/js/moment.js') }}"></script>
    <script src="{{ asset('plugins/moment/locale/zh-cn.js') }}"></script>
    <script src="{{ asset('plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js') }}"></script>
    <script src="{{ asset('plugins/summernote/js/summernote.js') }}"></script>
    <script src="{{ asset('plugins/summernote/lang/summernote-zh-CN.js') }}"></script>
    <script src="{{ asset('js/pages/article/add-edit.js') }}"></script>
@endsection
